import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xuance/constant.dart';
import 'package:xuance/widget/PolicyWidget.dart';
import 'package:xuance/widget/custom_textfield_widget.dart';

import 'login_logic.dart';

class LoginPage extends StatelessWidget {
  const LoginPage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<LoginLogic>();
    return Scaffold(
        backgroundColor: bgColor,
        body: SafeArea(
            child: Column(children: [
          Expanded(
              child: SingleChildScrollView(
                  child: Column(children: [
            const SizedBox(height: 150),
            Container(
                margin: const EdgeInsets.symmetric(horizontal: 15),
                decoration:
                    BoxDecoration(color: Colors.white, borderRadius: br5),
                child: Column(children: [
                  const Padding(
                      padding: EdgeInsets.symmetric(vertical: 30),
                      child: Text("网络安全&AI风险识别",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 18))),
                  Obx(() {
                    return getInput("请输入账号", logic.account.value, (t) {
                      logic.account.value = t;
                    }, false);
                  }),
                  const SizedBox(height: 15),
                  Obx(() {
                    return getInput("请输入密码", logic.password.value, (t) {
                      logic.password.value = t;
                    }, true);
                  }),
                  const SizedBox(height: 30),
                  GestureDetector(
                      onTap: logic.login,
                      child: Container(
                          margin: const EdgeInsets.symmetric(horizontal: 15),
                          padding: const EdgeInsets.symmetric(vertical: 10),
                          decoration: BoxDecoration(
                              color: c_green.withAlpha(250), borderRadius: br5),
                          child: const Center(
                              child: Text("登录",
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      color: Colors.white))))),
                  const SizedBox(height: 15)
                ]))
          ]))),
          Padding(
              padding: const EdgeInsets.all(8.0),
              child: GestureDetector(onTap: () {
                logic.check.value = !logic.check.value;
              }, child: Obx(() {
                return PolicyWidget(enable: true, isCheck: logic.check.value);
              })))
        ])));
  }

  getInput(
      String s, String value, Function(String)? onChanged, bool obscureText) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 20),
      decoration: BoxDecoration(color: inputColor, borderRadius: br5),
      child: CustomTextField(
          value: value,
          maxLines: 1,
          obscureText: obscureText,
          cursorColor: c_green.withAlpha(250),
          inputDecoration: InputDecoration(
              contentPadding:
                  const EdgeInsets.symmetric(horizontal: 10, vertical: 13),
              hintText: s,
              isDense: true,
              isCollapsed: true,
              border: InputBorder.none),
          onChanged: onChanged),
    );
  }
}
